package com.vasthu.core.service;

import com.vasthu.api.dao.CategoryDAO;
import com.vasthu.api.domain.Category;
import com.vasthu.api.service.CategoryManagerService;
import com.vasthu.core.dao.CategoryDAOImpl;
import com.vasthu.gui.VstTableItemSelectable;
import com.vasthu.utility.VstDBManager;
import java.util.*;
import java.sql.*;

public class CategoryManagerServiceImpl implements CategoryManagerService {

    private CategoryDAO catDao;

    public CategoryManagerServiceImpl() {
        catDao = new CategoryDAOImpl();
    }

    public boolean insertCategory(Category cat) {
        if (cat == null) {
            return false;
        }
        boolean ok = false;
        ok = catDao.insertCategory(cat);
        return ok;
    }

    public Category getCategoryById(long catId) {
        Category cat = null;
        cat = catDao.getCategoryById(catId);
        return cat;
    }

    public Category getCategoryByName(String catName) {
        Category cat = catDao.getCategoryByName(catName);
        return cat;
    }

    public boolean deleteCategoryById(long catId) {
        boolean ok = false;
        ok = catDao.deleteCategoryById(catId);
        return ok;
    }

    public List<String> getAllCategoryNames() {
        List<Category> catList = new ArrayList<Category>();
        List<String> catNameList = new ArrayList<String>();
        catList = catDao.getAllCategorys();
        for (Category cat : catList) {
            catNameList.add(cat.getCategoryName());
        }
        return catNameList;
    }

    public List<VstTableItemSelectable> getAllCategorysForTable() {
        List<Category> catList = new ArrayList<Category>();
        List<VstTableItemSelectable> dataList = new ArrayList<VstTableItemSelectable>();
        catList = catDao.getAllCategorys();
        for (Category cat : catList) {
            dataList.add(cat);
        }
        return dataList;
    }
}